package com.itheima.controller;

import com.itheima.domain.Book;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class BookController {
    //使用原生request对象传递参数
    @RequestMapping("/showPageAndData1")
    public String showPageAndData1(HttpServletRequest request) {
        request.setAttribute("name","itheima");
        return "page";
    }
    //使用Model形参传递参数
    @RequestMapping("/showPageAndData2")
    public String showPageAndData2(Model model) {
        model.addAttribute("name","itheima");
        Book book = new Book();
        book.setName("jjjjj");
        book.setPrice(5555.55);
        model.addAttribute("book",book);
        return "page";

    }

    //使用void形参传递参数，该对象还封装了页面信息
    @RequestMapping("/showPageAndData3")
    public ModelAndView showPageAndData3(ModelAndView modelAndView) {
        Book book = new Book();
        book.setName("dlsfj");
        book.setPrice(55.55);

        //添加key对value
        modelAndView.addObject("book",book);
        //添加数据的方式,key对value
        modelAndView.addObject("name","jockme");
        //s设置页面方式
        modelAndView.setViewName("page");
        //返回值设定成modelAndView对象
        return modelAndView;
    }

    //void对象支持转发的手工设定，该设定不会启用前缀后缀的页面拼接格式
    @RequestMapping("/showPageAndData4")
    public void showPageAndData4() {
    }

    //void对象支持重定向的手工设定，该设定不会启用前缀后缀的页面拼接格式
    @RequestMapping("/showPageAndData5")
    public void showPageAndData6() {
    }
}
